<template>
  <div class="chart-demo">
    <EChart 
      :options="chartOptions" 
      height="400px"
    />
    
    <EChart 
      :options="pieOptions" 
      height="400px"
    />

    <EChart 
      :options="lineOptions" 
      height="400px"
    />
  </div>
</template>

<script setup>
import { ref } from 'vue'
import EChart from '@/components/echart.vue'

const chartOptions = ref({
  title: {
    text: '示例图表'
  },
  tooltip: {},
  xAxis: {
    data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
  },
  yAxis: {},
  series: [{
    name: '销量',
    type: 'bar',
    data: [5, 20, 36, 10, 10, 20]
  }]
})

const pieOptions = ref({
  title: {
    text: '访问来源',
    left: 'center'
  },
  tooltip: {
    trigger: 'item',
    formatter: '{a} <br/>{b}: {c} ({d}%)'
  },
  legend: {
    orient: 'horizontal',
    bottom: '0'
  },
  series: [
    {
      name: '访问来源',
      type: 'pie',
      radius: ['40%', '70%'],
      avoidLabelOverlap: false,
      itemStyle: {
        borderRadius: 10,
        borderColor: '#fff',
        borderWidth: 2
      },
      label: {
        show: false,
        position: 'center'
      },
      emphasis: {
        label: {
          show: true,
          fontSize: '16',
          fontWeight: 'bold'
        }
      },
      labelLine: {
        show: false
      },
      data: [
        { value: 1048, name: '搜索引擎' },
        { value: 735, name: '直接访问' },
        { value: 580, name: '邮件营销' },
        { value: 484, name: '联盟广告' },
        { value: 300, name: '视频广告' }
      ]
    }
  ]
})

const lineOptions = ref({
  title: {
    text: '月度销售趋势',
    left: 'center'
  },
  tooltip: {
    trigger: 'axis',
    axisPointer: {
      type: 'cross',
      label: {
        backgroundColor: '#6a7985'
      }
    }
  },
  legend: {
    data: ['服装', '电子产品', '食品'],
    bottom: '0'
  },
  grid: {
    left: '3%',
    right: '4%',
    bottom: '60px',
    containLabel: true
  },
  xAxis: {
    type: 'category',
    boundaryGap: false,
    data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
  },
  yAxis: {
    type: 'value'
  },
  series: [
    {
      name: '服装',
      type: 'line',
      smooth: true,
      data: [140, 132, 141, 154, 190, 230, 210, 232, 201, 154, 190, 330],
      areaStyle: {
        opacity: 0.1
      }
    },
    {
      name: '电子产品',
      type: 'line',
      smooth: true,
      data: [120, 182, 191, 234, 290, 330, 310, 123, 442, 321, 90, 149],
      areaStyle: {
        opacity: 0.1
      }
    },
    {
      name: '食品',
      type: 'line',
      smooth: true,
      data: [320, 332, 301, 334, 390, 330, 320, 132, 101, 134, 90, 230],
      areaStyle: {
        opacity: 0.1
      }
    }
  ]
})
</script>

<style scoped>
.chart-demo {
  padding: 20px;
}
</style>
  